package com.bjpowernode.controller;

import com.bjpowernode.bean.Student;
import com.bjpowernode.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.lang.model.element.VariableElement;
import java.util.List;

@Controller
@RequestMapping(value = "/student")
public class StudentController {

    @Resource
    private StudentService studentService;

    //注册学生
    @RequestMapping("/addStudent.do")
    public ModelAndView addStudent(Student student){
        System.out.println(student.getName() + "   " + student.getAge());

        ModelAndView mv = new ModelAndView();
        String tips = "注册失败";

        int num = studentService.addStudent(student);
        System.out.println(num);
        if (num > 0) {
            tips = "学生【" + student.getName() + "】信息注册成功";
        }

        mv.addObject("tips", tips);
        mv.setViewName("result");

        return mv;
    }

    @RequestMapping("/queryStudent.do")
    @ResponseBody
    public List<Student> queryStudent(){
        List<Student> students = studentService.findStudents();
//        System.out.println(students);
        return students;
    }

}
